<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/

if (!defined ('EXPLAY')) exit;

/*if (is_cached ('admincp_news.html', 1)) $content = file_get_contents ($_SERVER['DOCUMENT_ROOT'].'/include/cache/admincp_news.html');
else {
	$content = build_admincp_news ();
	cache_file ('admincp_news.html', $content);
}

pats_table ('Новости Explay CMS', $content);*/

past_table ('Новости Explay CMS', build_admincp_news ());

		
function build_admincp_news () {
	
	$rss_news = @file_get_contents ('http://explay.su/api/rss/news/');
	
	if ($rss_news == '') return false;
	
	$xml = new SimpleXMLElement($rss_news);
	
	$res = '';
	
	for ($i = 0; $i < 4; $i++) {
		$header = $xml->channel[0]->item[$i]->title;
		$date = $xml->channel[0]->item[$i]->pubDate;
		$text = strip_tags ($xml->channel[0]->item[$i]->description);
		$link = $xml->channel[0]->item[$i]->link;
		
		$header = iconv ('UTF-8', 'CP1251', $header);
		$text = iconv ('UTF-8', 'CP1251', $text);
		$text = preg_replace ("#\<img(.+?)>#is", '', $text);
		
		if (strlen ($text) > 500) {
			$text = substr ($text, 0, 500);
		}
		$text .= "<a href=\"$link\">...</a>";
		
		$res .= "\r\n\t<p><a href=\"$link\"><strong>$header</strong></a><br><span style=\"color:silver\">$date</span><p />$text</p>";
	}
	
	return $res;
}